﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Tomato.Authentication
{
    public class RequireSessionLoginAttribute : ActionFilterAttribute
    {
        public RequireSessionLoginAttribute()
        {
            LoginActionName = "~/Home/Index";
        }

        public string LoginActionName { get; set; }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string userID = filterContext.HttpContext.User.Identity.Name;
            
            if (!SessionAuthenticator.IsSigneIn((Controller)filterContext.Controller))
            {
                filterContext.Result = new RedirectResult(LoginActionName);
            }

            base.OnActionExecuting(filterContext);
        }
    }
}
